! function () {
  const POST = function (url, data) {
    return new Promise((resolve, reject) => {
      let request = new XMLHttpRequest()
      request.open('post', url)
      request.setRequestHeader('content-type', 'application/json')
      request.onreadystatechange = function () {
        if (request.readyState === 4) {
          resolve(JSON.parse(request.response))
        }
      }
      request.send(JSON.stringify(data))
    })
  }
  const URL = 'https://louxiaoyuapi.etor.vip/api/doorway/v1/device/OpenDoorWX'
  const OPENID = 'oVUUc5NKao2SSq7L24notLR_aNB8'
  const DEVICE_NO_LIST = [
    'BCDDC2D71F24',
    '30AEA4CBD1C4',
    '30AEA4CBD2D8',
    '30AEA4C592D4'
  ]
  DEVICE_NO_LIST.forEach((deviceNo, i) => {
    POST(URL, {
      openid: OPENID,
      deviceNo: deviceNo
    }).then(res => {
      if (res.Code === 10000) {
        console.log(`${i+1}号门开启成功`)
      } else {
        throw new Error(res.data.Message)
      }
    }).catch(err => {
      console.log(`${i+1}号门开启失败`, err.message)
    })
  })
}()
